#include "mainwindow.h"

#include "antivirus/antiviruswork.h"
#include "antivirus/natiavparentwidget.h"
#include "antivirus/natiavwidget.h"
#include "antivirus/scanwidget.h"
#include <QStackedLayout>

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent),
      mMainLayout(new QStackedLayout(this)),
      mAntiVirusWidget(nullptr),
      mAntiVirusWork(nullptr)
{
    initUI();
    initconnect();
}

MainWindow::~MainWindow()
{

}


void MainWindow::initUI()
{
    if (!mAntiVirusWork) {
        mAntiVirusWork = new AntiVirusWork(this);
    }
    if (!mAntiVirusWidget) {
        mAntiVirusWidget = new NatiavParentWidget(mAntiVirusWork, this); 
    }

    mMainLayout->addWidget(mAntiVirusWidget);
    mMainLayout->addWidget(mAntiVirusWidget->antiVirusHomeWidget());
    mMainLayout->addWidget(mAntiVirusWidget->scanWidget());
    openAntiVirusHomePage();
}


void MainWindow::initconnect()
{
    connect(mAntiVirusWidget, SIGNAL(notifyOpenAntiVirusHomePage()), this, SLOT(openAntiVirusHomePage()));
    connect(mAntiVirusWidget, SIGNAL(notifyOpenScanVirusPage()), this, SLOT(openScanVirusPage()));
    connect(mAntiVirusWidget->scanWidget(), SIGNAL(onBackpage()), this, SLOT(openAntiVirusHomePage()));
}

void MainWindow::openAntiVirusHomePage()
{
    mMainLayout->setCurrentIndex(1);
}

void MainWindow::openScanVirusPage()
{
    mMainLayout->setCurrentIndex(2);
}

